import threading
import time
BUFF = 4
def producter(id, d):

    while(1):
        # d["lock"].acquire()
        print "producter"
        print d["status"]
        print ""
        if d["status"] < BUFF:
            d["status"] = d["status"] + 1
        time.sleep(10)

def consumer(id, d):
    time.sleep(2)
    while(1):
        time.sleep(1)
        # d["lock"].acquire()
        print "consumer"
        print d["status"]
        print ""
        if d["status"] > 0:
            d["status"] = d["status"] - 1
        # d["lock"].release()
        time.sleep(3)

d = {"status": 0, "lock": threading.Lock()}
th1 = threading.Thread(target = producter, args = (1, d))
th2 = threading.Thread(target = consumer, args = (2, d))
th1.daemon = True
th2.daemon = True

th1.start()
th2.start()

while(1):
    print "main"
    print d["status"]
    print ""
    time.sleep(2)
